Data Structures & Algorithms Using JavaScript by Hemant Jain

Data Structures & Algorithms Using JavaScript by Hemant Jain

Author:Hemant Jain [Jain, Hemant]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2017-05-17T04:00:00+00:00


Example 10.8:

Tree.prototype.NthPreOrder = function (index) {

var counter = [0];

if (typeof index === 'number')

return this.NthPreOrderUtil(this.root, index, counter);

else

throw new Error('invalid input arguments');

};

Tree.prototype.NthPreOrderUtil = function (node, index, counter) {

var retval;

if (node != null) {

counter[0]++;

if (counter[0] === index) {

return (node.value);

}

retval = this.NthPreOrderUtil(node.lChild, index, counter);

if(retval != null)

return retval;

retval = this.NthPreOrderUtil(node.rChild, index, counter);

if(retval != null)

return retval;

}

return null;

};



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.